<?php


use App\Library\Utils\Arr as ArrUtils;
use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class CommentSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'UserSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $users = $this->fetchAll("SELECT * FROM kg_user");

        $rows = [];
        for ($i = 0; $i < 50; $i++) {
            $rows[] = [
                'content' => $faker->text(25),
                'parent_id' => 0,
                'owner_id' => ArrUtils::rand($users)['id'],
                'to_user_id' => ArrUtils::rand($users)['id'],
                'item_id' => 1,
                'item_type' => 1,
                'client_type' => 1,
                'client_ip' => $faker->ipv4,
                'published' => 2,
                'reply_count' => 0,
                'like_count' => 0,
                'report_count' => 0,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_comment')->insert($rows)->saveData();
    }

}
